package com.dbh.company.buildbook;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.dbh.company.buildbook.bean.ConfigParam;
import com.dbh.company.buildbook.bean.ConfigVO;
import com.dbh.company.buildbook.bean.RespBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author dongbanghui
 * @create 2023/11/1
 */
public class ComplianceBackUp {

    private static final Logger LOGGER = LoggerFactory.getLogger(ComplianceBackUp.class);

    /**
     * 收集s3的key
     *
     * @return
     */
    public static RespBase getS3KeyList(Long projectNum) {

        ConfigParam configParam = new ConfigParam();
        configParam.setProjectNum(projectNum);
        String url = "http://pre-mr.ke.com/api/config/getConfigById";
        String body = HttpRequest
                .post(url)
                .body(JSONUtil.toJsonStr(configParam))
                .execute()
                .body();
        RespBase respBase = JSON.parseObject(body, RespBase.class);
        return respBase;
    }


    /**
     * 获取访问链接
     *
     * @param projectNum
     * @return
     */
    public static String getLink(Long projectNum) {
        String url = "https://mr.ke.com/3dmvp/#/" + projectNum + "/?source=editor";
        return url;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = ThreadUtil.newExecutor(50, 50);
        List<String> list = FileUtil.readLines("D:\\data\\work\\file\\楼书\\楼书1.0\\网信办\\projectNum.txt", "UTF-8");
        List<Long> longs = copyData(list);
        System.out.println(longs);
    }

    private static List<Long> copyData(List<String> list) {
        List<Long> strList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String item = list.get(i);
            RespBase s3KeyList = getS3KeyList(Convert.toLong(item));
            ConfigVO data = s3KeyList.getData();
            List<Long> configIdList = data.getConfigIdList();
            strList.addAll(configIdList);

        }
        return strList;
    }


}